<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%
	String title=(String)request.getAttribute("title");
%>
<title><%=title%></title>
<link rel="stylesheet" type="text/css" href="css/FinalProjectCSS.css"/>
<script type="text/javascript" src="table.js"></script>
<script type="text/javascript" src="js/MasterJS.js"></script>
<script type="text/javascript" src="validationWithJs.js"></script>
<script type="text/javascript">
	function flyToPage(task) {
		//alert("subjectTitle: "+document.forms[0].elements['modelSchedule.subjectTitle'].value);
		//alert("fileName: "+document.forms[0].elements['modelFileSch.fileName'].value);
		
		var tempTask = document.forms[0].elements['task'].value;
		if (tempTask == "uploadFileSubject") {
			if (checkFileSizeUpload() == 1 && checkFileNameLength()) {
				var r = confirm("Upload " +document.forms[0].elements['modelFileSch.fileName'].value+ " ?");
				document.forms[0].submit();	
			}
		} else {
			if (checkFileSizeEdit() && checkFileNameLength()) {
				var r = confirm("Upload " +document.forms[0].elements['modelFileSch.fileName'].value+ " ?");
				document.forms[0].submit();	
			}
		}
	}
	
	function checkFileSizeUpload() {
	    var input, file;
		var checkSize = 0; //kalo blm milih file
	   
	    input = document.getElementById('theFile');
	    if (input != null)  {
	    	if (input.files != null) {
	    		if (input.files[0]!=null){
		    		if (input.files[0].size > 0) {
		    			//alert("file size: " + input.files[0].size);
		    			file = input.files[0];
		    	        //alert("File " + file.name + " is " + file.size + " bytes in size");
		    	        if (input.files[0].size <= 5000000) {
		    	        	checkSize = 1; //kalo file size bnr
		    	        } else {
		    	        	checkSize = 2; //kalo file size slh
		    	        	alert("File size must be less than or equals 5MB!");
		    	        }
		    		} 
	    		}
	    	}
	    }
	    
	    if (checkSize == 0) {
	    	alert("Choose a file!");	
	    }
	    		
	    return checkSize;
	}
	
	function checkFileSizeEdit() {
	    var input, file;
		var checkSize = true;
	    
	    input = document.getElementById('theFile');
	    if (input != null)  {
	    	if (input.files != null) {
	    		if (input.files[0]!=null){
		    		if (input.files[0].size > 0) {
		    			//alert("file size: " + input.files[0].size);
		    			file = input.files[0];
		    	        //alert("File " + file.name + " is " + file.size + " bytes in size");
		    	        if (input.files[0].size > 5000000) {
		    	        	alert("File size must be less than or equals 5MB!");
		    	        	checkSize = false;
		    	        } 
		    		} 
	    		}
	    	}
	    }
	    		
	    return checkSize;
	}
	
	function checkFileNameLength() {
		var str = document.forms[0].elements['modelFileSch.fileName'].value;
		if (str.length > 100) {
			alert("File name must be less than or equals 100 characters!");
			return false;
		}
		
		return true;
	}
	
	function backToListSch() {
		<%
			session.removeAttribute("result");
		%>
		document.forms[0].task.value = "backToListSchedule";
		document.forms[0].submit();
	}
	
	function setFileName(){
		var str = document.forms[0].elements['theFile'].value;
		var res = str.substr(str.lastIndexOf("\\")+1);
		document.forms[0].elements['modelFileSch.fileName'].value = res;
	}
</script>
</head>
<body>
	<center>
		<table width="100%" class="bodyTable boxShadow">
			<!-- HEADER -->
			<tr>
				<td colspan="2"><%@include file="/include/Header.jsp"%></td>
			</tr>
			
			<!-- CONTAINER -->
			<tr>
				<td rowspan="2" width="200px" class="navigationBox"><%@include file="/include/Navigation.jsp"%></td>
				<td align="left" class="headerBox blueBackground">
					ACE Management > 
					<a href="/WebFinalProject/Schedule.do">Class Schedule ></a> <%=title%>
				</td>
			</tr>
			<tr>
				<td align="center" class="contentStyle"><br>
					<html:form action="/Schedule" method="post" enctype="multipart/form-data">
						<html:hidden property="task" name="scheduleForm" />
						<html:hidden property="modelFileSch.batchClassId" name="scheduleForm" />
						<html:hidden property="modelSchedule.subjectTitle" name="scheduleForm" />
						<html:hidden property="modelFileSch.fileId" name="scheduleForm" />
						<html:hidden property="selectedBatchId" name="scheduleForm" />
						<%-- <html:hidden property="totalPage" name="scheduleForm"/> --%>
						<html:hidden property="currentPage" name="scheduleForm"/>
							
						<%-- <bean:write property="task" name="scheduleForm" /> <br>					
						<bean:write property="modelFileSch.fileId" name="scheduleForm" /> <br>
						<bean:write property="modelFileSch.batchClassId" name="scheduleForm" /> <br>
						<bean:write property="modelSchedule.subjectTitle" name="scheduleForm" /> <br>
						<bean:write property="modelFileSch.uploaderId" name="scheduleForm" /> <br>
						<bean:write property="selectedBatchId" name="scheduleForm" /> <br> --%>
						
						<table width="350px" class="boxShadow"> 
							<tr>
								<td colspan="2" class="headerBox formHeaderBackground" align="center"><%=title%></td>
							</tr>
							<tr>
								<td style="vertical-align: middle; height:130px;">
									<table align="center" style="border-spacing: 5px;">
										<tr>
											<td style="vertical-align: middle;" width="70px">Select File</td>
											<td><input type="file" name="theFile" id="theFile" onchange="javascript:setFileName();"/></td>
										</tr>
							
										<tr>
											<td style="vertical-align: middle;">File Name</td>
											<td><html:text property="modelFileSch.fileName" name="scheduleForm" styleClass="textLarge" readonly="true"></html:text></td>
										</tr>
										
										<tr>
											<td style="vertical-align: middle;">Description</td>
											<td><html:textarea rows="5" property="modelFileSch.description" name="scheduleForm" styleClass="textLarge" onkeyup="javascript:cekMaxLength('modelFileSch.description', 100);"></html:textarea></td>
										</tr>
									</table>
									<table align="center" style="border-spacing: 5px;">
										<tr>
											<td colspan="3" align="center" class="formListStyle">
												<table title="save" class="buttonStyle" style="cursor: pointer;" onclick="javascript:flyToPage();">
													<tr>
														<td style="vertical-align: middle;"><img src="images/saveButton.png"/></td>
														<td style="vertical-align: middle;">&nbsp;<b>Save</b></td>
													</tr>
												</table>
											</td>
											<td colspan="3" align="center" class="formListStyle">
												<table title="cancel" class="buttonStyle" style="cursor: pointer;" onclick="javascript:backToListSch();">
													<tr>
														<td style="vertical-align: middle;"><img src="images/cancelButton.png"/></td>
														<td style="vertical-align: middle;">&nbsp;<b>Cancel</b></td>
													</tr>
												</table>												
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</html:form><br><br>
				</td>
			</tr>
			
			<!-- FOOTER -->
			<tr>
				<td align="center" colspan="2" class="headerBox blueBackground">&copy; OME.2013.All Rights Reserved.</td>
			</tr>
		</table>
	</center>
</body>
</html>